#include <iostream>
#include "Array2d.h"

using namespace std;



Array2d::Array2d(int rows, int cols)
{
arr = new ElementType*[rows];
for (int i = 0; i < rows; i++)
	arr[i] = new ElementType[cols];
numRows = rows;
numCols = cols;
}

Array2d::Array2d(Array2d& a)
{
numRows = a.numRows;
numCols = a.numCols;

arr = new ElementType*[numRows];
for (int i = 0; i < numRows; i++)
	arr[i] = new ElementType[numCols];

for (int r = 0; r < numRows; r++)
	for (int c = 0; c < numCols; c++)
		arr[r][c] = a.arr[r][c];
}

Array2d::~Array2d()
{
	for(int i = 0; i < numRows; i++)
	{
		delete [] arr[i];
	}

	delete [] arr;
}

ElementType& Array2d::elementAt (int r, int c)
{
if (r >= 0 && r <= numRows && c >= 0 && c <= numCols)
	return arr[r][c];
else
	{
	throw InvalidIndexException();
	}
}
